package br.eti.busarello;

import java.awt.Component;
import java.util.Collection;
import java.util.Map;
import java.util.TreeMap;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException;

import org.pushingpixels.substance.api.skin.AutumnSkin;
import org.pushingpixels.substance.api.skin.BusinessBlackSteelSkin;
import org.pushingpixels.substance.api.skin.BusinessBlueSteelSkin;
import org.pushingpixels.substance.api.skin.BusinessSkin;
import org.pushingpixels.substance.api.skin.CeruleanSkin;
import org.pushingpixels.substance.api.skin.ChallengerDeepSkin;
import org.pushingpixels.substance.api.skin.CremeCoffeeSkin;
import org.pushingpixels.substance.api.skin.CremeSkin;
import org.pushingpixels.substance.api.skin.DustCoffeeSkin;
import org.pushingpixels.substance.api.skin.DustSkin;
import org.pushingpixels.substance.api.skin.EmeraldDuskSkin;
import org.pushingpixels.substance.api.skin.GeminiSkin;
import org.pushingpixels.substance.api.skin.GraphiteAquaSkin;
import org.pushingpixels.substance.api.skin.GraphiteGlassSkin;
import org.pushingpixels.substance.api.skin.GraphiteSkin;
import org.pushingpixels.substance.api.skin.MagellanSkin;
import org.pushingpixels.substance.api.skin.MistAquaSkin;
import org.pushingpixels.substance.api.skin.MistSilverSkin;
import org.pushingpixels.substance.api.skin.ModerateSkin;
import org.pushingpixels.substance.api.skin.NebulaBrickWallSkin;
import org.pushingpixels.substance.api.skin.NebulaSkin;
import org.pushingpixels.substance.api.skin.OfficeBlack2007Skin;
import org.pushingpixels.substance.api.skin.OfficeBlue2007Skin;
import org.pushingpixels.substance.api.skin.OfficeSilver2007Skin;
import org.pushingpixels.substance.api.skin.RavenSkin;
import org.pushingpixels.substance.api.skin.SaharaSkin;
import org.pushingpixels.substance.api.skin.SubstanceAutumnLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceBusinessBlackSteelLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceBusinessBlueSteelLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceBusinessLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceCeruleanLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceChallengerDeepLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceCremeCoffeeLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceCremeLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceDustCoffeeLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceDustLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceEmeraldDuskLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceGeminiLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceGraphiteAquaLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceGraphiteGlassLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceGraphiteLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceMagellanLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceMistAquaLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceMistSilverLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceModerateLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceNebulaBrickWallLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceNebulaLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceOfficeBlack2007LookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceOfficeBlue2007LookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceOfficeSilver2007LookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceRavenLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceSaharaLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceTwilightLookAndFeel;
import org.pushingpixels.substance.api.skin.TwilightSkin;

public class ComboLookAndFeels extends JComboBox<String>{
  private static final long serialVersionUID = 1L;
  
	private Map<String, String> mapLooks = new TreeMap<String, String>();
	
	public ComboLookAndFeels() {
		mapLooks.put(BusinessSkin.NAME, SubstanceBusinessLookAndFeel.class.getName());
		mapLooks.put(BusinessBlackSteelSkin.NAME, SubstanceBusinessBlackSteelLookAndFeel.class.getName());
		mapLooks.put(BusinessBlueSteelSkin.NAME, SubstanceBusinessBlueSteelLookAndFeel.class.getName());
		mapLooks.put(CremeSkin.NAME, SubstanceCremeLookAndFeel.class.getName());
		mapLooks.put(ModerateSkin.NAME, SubstanceModerateLookAndFeel.class.getName());
		mapLooks.put(SaharaSkin.NAME, SubstanceSaharaLookAndFeel.class.getName());
		mapLooks.put(OfficeBlack2007Skin.NAME, SubstanceOfficeBlack2007LookAndFeel.class.getName());
		mapLooks.put(OfficeBlue2007Skin.NAME, SubstanceOfficeBlue2007LookAndFeel.class.getName());
		mapLooks.put(OfficeSilver2007Skin.NAME, SubstanceOfficeSilver2007LookAndFeel.class.getName());
		mapLooks.put(RavenSkin.NAME, SubstanceRavenLookAndFeel.class.getName());
		mapLooks.put(GraphiteSkin.NAME, SubstanceGraphiteLookAndFeel.class.getName());
		mapLooks.put(GraphiteGlassSkin.NAME, SubstanceGraphiteGlassLookAndFeel.class.getName());
		mapLooks.put(GraphiteAquaSkin.NAME, SubstanceGraphiteAquaLookAndFeel.class.getName());
		mapLooks.put(ChallengerDeepSkin.NAME, SubstanceChallengerDeepLookAndFeel.class.getName());
		mapLooks.put(EmeraldDuskSkin.NAME, SubstanceEmeraldDuskLookAndFeel.class.getName());
		mapLooks.put(NebulaSkin.NAME, SubstanceNebulaLookAndFeel.class.getName());
		mapLooks.put(NebulaBrickWallSkin.NAME, SubstanceNebulaBrickWallLookAndFeel.class.getName());
		mapLooks.put(MistSilverSkin.NAME, SubstanceMistSilverLookAndFeel.class.getName());
		mapLooks.put(MistAquaSkin.NAME, SubstanceMistAquaLookAndFeel.class.getName());
		mapLooks.put(AutumnSkin.NAME, SubstanceAutumnLookAndFeel.class.getName());
		mapLooks.put(CeruleanSkin.NAME, SubstanceCeruleanLookAndFeel.class.getName());
		mapLooks.put(CremeCoffeeSkin.NAME, SubstanceCremeCoffeeLookAndFeel.class.getName());
		mapLooks.put(DustSkin.NAME, SubstanceDustLookAndFeel.class.getName());
		mapLooks.put(DustCoffeeSkin.NAME, SubstanceDustCoffeeLookAndFeel.class.getName());
		mapLooks.put(TwilightSkin.NAME, SubstanceTwilightLookAndFeel.class.getName());
		mapLooks.put(MagellanSkin.NAME, SubstanceMagellanLookAndFeel.class.getName());
		mapLooks.put(GeminiSkin.NAME, SubstanceGeminiLookAndFeel.class.getName());

		LookAndFeelInfo[] installedLookAndFeels = UIManager.getInstalledLookAndFeels();
		
		for (LookAndFeelInfo lookAndFeelInfo : installedLookAndFeels) {
			mapLooks.put(lookAndFeelInfo.getName(), lookAndFeelInfo.getClassName());
    }
		
		Collection<String> names = mapLooks.keySet();
		
		setModel(new DefaultComboBoxModel<String>(names.toArray(new String[names.size()])));

	}
	
	public String getSelected() {
	  return (String) getSelectedItem();
	}
	
	public String getLookAndFeelClassNameSelected(){
		String className = null;
		String selected = getSelected();
		if(selected != null){
			className = mapLooks.get(selected);
		}
		return className;
	}
	
	public void apllyLookAndFeel(Component component){
		String className = getLookAndFeelClassNameSelected();
		
		if(className != null){
			
			try {
	      UIManager.setLookAndFeel(className);
      } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
	      e.printStackTrace();
      }
			
			SwingUtilities.updateComponentTreeUI(component);
			
		}
	}
	
}
